function [pImg] = Img2PImg( img, rf)
% Input
% img: HxWxBand
% rf: receptive field
% Output
% vecs: DxN

halfRF = floor(rf/2);
[h,w,band] = size(img);
pImg = zeros(h,w,rf*rf*band);

for row=halfRF+1:h-halfRF
    for col=halfRF+1:w-halfRF
        patch = img( row-halfRF:row+halfRF, col-halfRF:col+halfRF, :);
        vec = reshape(patch,rf*rf*band,1);
        pImg(row,col,:) = vec;
    end
end

% Boundary of the image 
for row =1:halfRF
    for col = 1:w
        if col<=halfRF+1
          pImg(row,col,:) = pImg(halfRF+1,halfRF+1,:);
        end
        if col>=w-halfRF
          pImg(row,col,:) = pImg(halfRF+1,w-halfRF,:) ;
        end
        if col>halfRF+1 && col<w-halfRF
            pImg(row,col,:) = pImg(halfRF+1,col,: );
        end
    end
end

for row = halfRF+1:h-halfRF
    for col = 1:halfRF
        pImg(row,col,:) = pImg(row,halfRF+1,:);
    end
end

for row = halfRF+1:h-halfRF
    for col = w-halfRF+1:w
        pImg(row,col,:) = pImg(row,w-halfRF,:);
    end
end

for row =h-halfRF+1:h
    for col = 1:w
        if col<=halfRF+1
          pImg(row,col,:) = pImg(h-halfRF,halfRF+1,:);
        end
        if col>=w-halfRF
          pImg(row,col,:) = pImg(h-halfRF,w-halfRF,:) ;
        end
        if col>halfRF+1 && col<w-halfRF
            pImg(row,col,:) = pImg(h-halfRF,col,: );
        end
    end
end

    
end